package com.rongshu.view.home.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.home.contract.InputCommentView;
import com.rongshu.view.home.entity.ContentClass;

import okhttp3.ResponseBody;
import rx.Subscriber;

/**
 * created by zhengweis on 2019/7/12.
 * description：
 */
public class InputCommentPresenter extends BasePresenter<InputCommentView> {
    public InputCommentPresenter(Context context) {
        super(context);
    }

    /**
     * 文章评论/评论回复/回复回复
     */
    public void postCommentOrReplyAdd(int user_id, int contribute_id, int comment_id,
                                      int reply_id, String sign, ContentClass contentClass) {
        RetorfitService.postCommentOrReplyAdd(user_id, contribute_id, comment_id, reply_id, sign, contentClass)
                .compose(getView().<ResponseBody>bindToLife())
                .subscribe(new Subscriber<ResponseBody>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(ResponseBody body) {
                        if (getView() != null) {
                            getView().onPostCommentOrReplyAdd(body);
                        }
                    }
                });
    }
}
